{extend name="public/base"/}
{block name="body"}
<title>添加企业文化 - 企业文化管理 -</title>
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal section" id="form-admin-add">
			<section>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">标题：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<input type="text" class="input-text" value="" id="title" name="title">
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">标语：</label>
						<div class="formControls col-xs-8 col-sm-9">
							<textarea rows="6" style="width:100%" name="slogan"></textarea>
						</div>
					</div>
					<div class="row cl">
						<label class="form-label col-xs-3 col-sm-2">图片：</label>
						<div class="formControls col-xs-8 col-sm-9">
			                <div style="position:relative;" id="drop_area"></div>
			                <p style="color:#ccc;font-size:12px;">建议尺寸宽高:27:27</p>
						</div>
					</div>
			</section>
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input id="submit" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
				</div>
			</div>
	</form>

	
</article>


<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/public/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="/public/static/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="/public/static/lib/jquery.validation/1.14.0/messages_zh.js"></script> 
<script type="text/javascript" src="/public/static/js/upload.js"></script>
<script type="text/javascript">
var formData = new FormData();
var icon='';
var dragImgUpload = new DragImgUpload("#drop_area",{
    callback:function (files) {
        //回调函数，可以传递给后台等等
        if(files[0].size<3145728){
	        var file = files[0];
	        formData.append("file",file);
        }else{
        	alert('出错');
        	location.replace(location.href);
        }
    }
});
$("#submit").click(function() {
	layer.load(1, {
	  shade: [0.1,'#fff'] //0.1透明度的白色背景
	});
	var title=$("input[name=title]").val();
	var slogan=$("textarea[name=slogan]").val();
	if(formData.get("file")){
		$.ajax({
	          type: 'POST',
	          url: "{:url('uploadtmd')}",
	          data:formData,
	          contentType: false, /*不可缺*/
	          processData: false, /*不可缺*/
	          success: function(response){
	            if(response.code==200){
	            	icon=response.photo;
	            	$.ajax({
					    type: 'POST',
					    url: "{:url('culture_add')}",
					    data: {title:title,icon:icon,slogan:slogan},
					    success: function(resdata){
					        if(resdata.code==200){
								layer.msg(resdata.msg,{icon:1,time:1000});
								setTimeout("parent.location.reload()",1000);
					        }else{
								layer.msg(resdata.msg,{icon:2,time:3000});
					        }
					    },
					    error: function(){
							layer.msg('数据保存失败',{icon:2,time:3000});
					    }
					})
	            }else{
	              alert(response.msg);
	            }
	          },
	          error: function(err){

	          }
	    })
	}else{
		$.ajax({
		    type: 'POST',
		    url: "{:url('culture_add')}",
		    data: {title:title,icon:icon,slogan:slogan},
		    success: function(resdata){
		        if(resdata.code==200){
					layer.msg(resdata.msg,{icon:1,time:1000});
					setTimeout("parent.location.reload()",1000);
		        }else{
					layer.msg(resdata.msg,{icon:2,time:3000});
		        }
		    },
		    error: function(){
				layer.msg('数据保存失败',{icon:2,time:3000});
		    }
		})
	}
	
    
})

</script> 

{/block}